package com.icid.store.command
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.icid.store.business.delegate.CategoryDelegate;
	import com.icid.store.event.GetCategoryListEvent;
	import com.icid.store.model.CategoryModelLocator;
	import com.icid.store.vo.CategoryVO;
	
	import mx.rpc.IResponder;

	public class GetCategoryListCommand extends CommandBase implements ICommand, IResponder
	{
		private var delegate:CategoryDelegate;
		private var getCategoryListEvent:GetCategoryListEvent;
		private var categoryModel:CategoryModelLocator = CategoryModelLocator.getInstance();
		public function GetCategoryListCommand()
		{
			super();
			delegate  = new CategoryDelegate(this);
		}
		
		override public function execute(event:CairngormEvent):void
		{
			getCategoryListEvent = GetCategoryListEvent(event);
			delegate.read(getCategoryListEvent.categoryFilter);
		}
		
		override public function result(data:Object):void
		{
//			trace(data.result);
			categoryModel.categoryList.removeAll();
			for(var i:int=0;i<data.result.length;i++)
			{
				var categoryVO:CategoryVO = new CategoryVO();
				categoryVO.id = data.result[i].id;
				categoryVO.title = data.result[i].title;
				categoryVO.description = data.result[i].description;
				categoryVO.time = data.result[i].time;
				categoryModel.categoryList.addItem(categoryVO);
			}
			categoryModel.categoryList.refresh();
		}
		
	}
}